<template>
  <normal-layout>
    <div class="container">
      <el-tabs style="margin: 10px;">
        <el-tab-pane label="普通订单">
          <el-form :model="buyForm" label-position="left" style="margin-left:35%; width: 30%;">
            <el-form-item label="客户">
              <el-input v-model="buyForm.cno" style="width: 80%" disabled></el-input>
            </el-form-item>
            <el-form-item label="车号">
              <el-input v-model="buyForm.vno" style="width: 80%" ></el-input>
            </el-form-item>
            <el-form-item label="价格">
              <el-input v-model="buyForm.price" style="width: 80%" ></el-input>
            </el-form-item>
            <el-form-item label="途径">
              <el-input v-model="buyForm.way" style="width: 80%" ></el-input>
            </el-form-item>
            <el-form-item label="单号">
              <el-input v-model="buyForm.subno" style="width: 80%" ></el-input>
            </el-form-item>
            <el-form-item style="text-align: right">
              <el-button @click="submitBuyForm" style="margin-right: 50px">生成订单</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="预订请求">
          <el-form :model="subscribeForm" label-position="left" style="margin-left:35%; width: 30%; ">
            <el-form-item label="客户">
              <el-input v-model="subscribeForm.cno" style="width: 80%" disabled></el-input>
            </el-form-item>
            <el-form-item label="车系">
              <el-input v-model="subscribeForm.model" style="width: 80%" ></el-input>
            </el-form-item>
            <el-form-item label="配置">
              <el-input v-model="subscribeForm.config" style="width: 80%" ></el-input>
            </el-form-item>
            <el-form-item label="颜色">
              <el-input v-model="subscribeForm.color" style="width: 80%" ></el-input>
            </el-form-item>
            <el-form-item label="定金">
              <el-input v-model="subscribeForm.price" style="width: 80%" ></el-input>
            </el-form-item>
            <el-form-item style="text-align: right">
              <el-button @click="submitSubscribeForm" style="margin-right: 50px">生成请求</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
      </el-tabs>
    </div>
  </normal-layout>
</template>

<script>
    import NormalLayout from "../../../layouts/NormalLayout";
    import axios from "../../../.nuxt/axios";
    export default {
        name: "NewOrder",
      components: {NormalLayout},
      data(){
          return{
            /*客户名称*/
            cno:'',
            /*车辆库存*/

            /*购买表单和预定表单*/
            buyForm:{
              cno:'',
              vno:'',
              price:'',
              way:'',
              subno:'',
            },

            subscribeForm:{
              cno:'',
              model:'',
              config:'',
              color:'',
              price:'',
            },
          }
      },
      created() {
          this.cno=this.$route.query.cno;
          this.buyForm.cno=this.cno;
          this.subscribeForm.cno=this.cno;
      },
      methods:{
          /*提交购买订单*/
        submitBuyForm(){
          this.$confirm('确定生成购买订单？', '生成订单',{
            confirmButtonText:'确定',
            cancelButtonText:'取消',
            type:'warning'
          }).then(() => {
            let mydata=this.buyForm;
            console.log(this.buyForm);
            this.$axios.post('/new_border',mydata).then((res)=>{
              if(res==='1'){
                this.$message({
                  type: 'success',
                  message: '成功'
                });
              }
              this.$router.push({path:'/Customer'});
            });
          })
        },
        /*提交订购请求*/
        submitSubscribeForm(){
          this.$confirm('确定生成订购请求？', '生成',{
            confirmButtonText:'确定',
            cancelButtonText:'取消',
            type:'warning'
          }).then(() => {
            let mydata=this.subscribeForm;
            console.log(this.subscribeForm);
            this.$axios.post('/new_sub',mydata).then((res)=>{
              if(res==='1'){
                this.$message({
                  type: 'success',
                  message: '成功'
                });
              }
              this.$router.push({path:'/Customer'});
            });
          })
        },
      }
    }
</script>

<style scoped>
  .container{
    justify-content: center;
    align-items: center;
    text-align: center;
  }
</style>
